<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">文件：</label>
                            <div class="col-sm-8">
                                <table class="table table-hover col-sm-8">
                                    <thead>
                                    <tr>
                                        <th style="text-align:center;">文件名</th>
                                        <th style="text-align:center;">文件类型</th>
                                        <th style="text-align:center;">文件大小</th>
                                    </tr>
                                    </thead>
                                    <tbody id="tbody0" th:each="file,userStat:${fileList}">
                                        <tr>
                                            <td style="text-align:center;" th:text="${file.filename}"></td>
                                            <td style="text-align:center;" th:text="${file.filetype}"></td>
                                            <td style="text-align:center;" th:text="${file.filesizeStr}"></td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                            <input type="hidden" name="ids" id="ids" th:value="${idsStr}">
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">接收人：</label>
                            <div class="col-sm-8">
                                <input class="btn btn-primary" type="button" value="选择接收人" onclick="selectUser('3');">
                                <input class="btn btn-danger" type="button" value="清空接收人" onclick="emptyUser('3');">
                                <table class="table table-hover col-sm-8">
                                    <thead>
                                    <tr>
                                        <th style="text-align:center;">姓名</th>
                                        <th style="text-align:center;">用户名</th>
                                        <th style="text-align:center;">所属部门</th>
                                    </tr>
                                    </thead>
                                    <tbody id="tbody1">
                                    </tbody>
                                </table>
                            </div>
                            <input type="hidden" name="targetIds" id="targetIds">
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">审批人：</label>
                            <div class="col-sm-8">
                                <input class="btn btn-primary" type="button" value="选择审批人" onclick="selectUser('2');">
                                <input class="btn btn-danger" type="button" value="清空审批人" onclick="emptyUser('2');">
                                <table class="table table-hover col-sm-8">
                                    <thead>
                                    <tr>
                                        <th style="text-align:center;">姓名</th>
                                        <th style="text-align:center;">用户名</th>
                                        <th style="text-align:center;">所属部门</th>
                                    </tr>
                                    </thead>
                                    <tbody id="tbody2">
                                    </tbody>
                                </table>
                            </div>
                            <input type="hidden" name="auditid" id="auditid">
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">发送备注：</label>
                            <div class="col-sm-8">
                                <textarea id="sendcmt" name="sendcmt" class="form-control"></textarea>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button type="button" class="btn btn-primary" onclick="save();">提交</button>
                            </div>
                        </div>

                    </form>
                </div>
            </div>
        </div>
    </div>

</div>
<div th:include="include :: footer"></div>
<script>
    //选择用户
    function selectUser(roleId) {
        layer.open({
            type : 2,
            title : '选择用户',
            maxmin : true,
            shadeClose : false, // 点击遮罩关闭层
            area : [ '60%', '60%' ],
            content : '/sys/userFile/toselectUser?roleId='+roleId // iframe的url
        });
    }

    //清空用户
    function emptyUser(roleId) {
        if(roleId == '3') {
            $("#targetIds").val("");
            $("#tbody1").html("");
        }else {
            $("#auditid").val("");
            $("#tbody2").html("");
        }
    }

    function save() {
        var targetIds = $("#targetIds").val();
        if(!targetIds) {
            parent.layer.alert("请选择接收人")
            return;
        }
        var auditid = $("#auditid").val();
        if(!auditid && getSetValue()) {
            parent.layer.alert("请选择审批人")
            return;
        }
        var sendcmt = $("#sendcmt").val();
        if(!sendcmt) {
            parent.layer.alert("请输入发送备注")
            return;
        }else {
            if(sendcmt.length > 100) {
                parent.layer.alert("发送备注不能超过100个字符")
                return;
            }
        }
        $.ajax({
            cache : true,
            type : "POST",
            url : "/sys/userFile/batchSend",
            data : $('#signupForm').serialize(),// 你的formid
            async : false,
            error : function(request) {
                parent.layer.alert("Connection error");
            },
            success : function(data) {
                if (data.code == 0) {
                    parent.layer.msg("操作成功");
                    var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                    parent.layer.close(index);
                    parent.getMyFile(0,null,"");
                } else {
                    parent.layer.alert(data.msg)
                }
            }
        });
    }

    function getSetValue() {
        var flag = true;
        $.ajax({
            type : "POST",
            url : "/sys/set/getSetValue?type=enableFileAuidtOn",
            async : false,
            success : function(data) {
                //获取是否启用文件审批(0：关闭 1：打开)
                if (data != null && data != '') {
                    if(data.setValue == 0) {
                        flag = false;
                    }
                }
            }
        });
        return flag;
    }
</script>
</body>
</html>